/*
	Copyright (C) 2008 by Jean-FranÁois Geyelin
	jfgeyelin@gmail.com

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the
	Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/



#include "settings.h"
#include "Menu.h"
#include "globals.h"
#include "SurfaceHandler.h"
#include "handleEvents.h"
#include "resolutionMenu.h"
#include "soundMenu.h"
#include "changePlayerName.h"


void settingsMenu(void) {

  	SDL_Rect **modes;
	modes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);

	Menu optionMenu;
	Settings s;
	loadSettings(&s);

	optionMenu.addTitle("Settings");
	optionMenu.addMenuItem("Change resolution",1);

	optionMenu.addMenuItem("",2);


//if there are some sound effects OR there is some music, add the item
#ifdef NO_SOUND_EFFECT
#ifndef NO_MUSIC
	optionMenu.addMenuItem("Change volume",3);
#else
#endif
#else
    optionMenu.addMenuItem("Change volume",3);
#endif




    optionMenu.addMenuItem("Change player's name",4);



    boo:



	if (s.fullScreen) {
        optionMenu.changeMenuItem(2,"Go in windowed mode");
        optionMenu.setIcons(5,"icon_resolution.png","icon_window.png","icon_volume.png","empty.png","icon_back.png");
	}
	else {
        optionMenu.changeMenuItem(2,"Go in full screen");
        optionMenu.setIcons(5,"icon_resolution.png","icon_fullscreen.png","icon_volume.png","empty.png","icon_back.png");
	}

    SurfaceHandler::colorScreen(255,255,255);




	int menuResult = optionMenu.launch();


	switch (menuResult) {
		case 1:
			resolutionMenu();
			goto boo;
		case 2:
			s.fullScreen = !s.fullScreen;
	        writeSettings(&s);
	        ScreenClass::getInstance()->createNewScreen();
	        goto boo;
		case 3:
            soundMenu();
	        goto boo;
        case 4:
            changePlayerName();
            goto boo;
        default:
            break;
	}

	getSettings();
}
